Repository navigation
fix(push): surface account lookup errors instead of reporting missing handle - #5950
Open
RainyMarks wants to merge 1 commit into
Open
RainyMarks wants to merge 1 commit into
RainyMarks wants to merge 1 commit into
Conversation
… handle Distinguish registry/network account lookup failures from a successfully retrieved account that lacks a tscircuit_handle: - Add optional throwOnError and sessionToken options to fetchAccount() and validate that the accounts/get response contains an account object, while preserving the default null fallback for offline-tolerant callers. - Update pushSnippet() to verify TSCIRCUIT_TOKEN accounts with throwOnError so HTTP errors (401/403/429/503), network failures, and malformed payloads report an account verification failure instead of a missing handle. - Update auth whoami to report account lookup failures with a nonzero exit code instead of printing @(not set) and exiting 0. - Update auth login to stay offline-tolerant while avoiding @undefined and stale cached handles when TSCIRCUIT_TOKEN is set. - Add offline unit tests for fetchAccount, pushSnippet, auth whoami, and auth login. Closes tscircuit#5275
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #5275
Fixes
tsci pushmisreporting"You need to set your tscircuit handle to publish packages"when looking up the authenticated account forTSCIRCUIT_TOKENfails due to HTTP errors (such as 503, 401session_expired, 403, 429), network/timeout errors, or malformed responses.Root Cause
fetchAccount()inlib/registry-api/fetch-account.tscaught every request and JSON-parsing error and returnednull, and did not validate that theaccounts/getresponse contained anaccountobject.pushSnippet()inlib/shared/push-snippet.tstreated any falsy(await fetchAccount())?.tscircuit_handleas proof that the account lacked a handle, discarding the underlying registry/network error andgetRegistryApiKy()'s expired-session guidance.tsci auth whoamito print@(not set)with exit code0on lookup failure, andtsci auth loginto printAlready logged in as @undefined!when no saved handle was present.Changes
lib/registry-api/fetch-account.ts:{ sessionToken?: string; throwOnError?: boolean }parameter tofetchAccount()so existing offline-tolerant callers (such astsci initandtsci auth login) keep their defaultnullfallback while strict callers can surface errors.accounts/getpayload contains a non-nullaccountobject (throwing a descriptive error when missing or when anerrorpayload is returned).lib/registry-api/endpoint-types.ts:EndpointResponse["accounts/get"]["account"]["tscircuit_handle"]tostring | nullto match accounts without a handle set.lib/shared/push-snippet.ts:fetchAccount({ sessionToken, throwOnError: true })whenTSCIRCUIT_TOKENis set, reportingCould not verify your account for publishing: <error>with exit code1on lookup failure without falling back to a cachedtscircuitHandle."You need to set your tscircuit handle to publish packages"strictly for accounts that were successfully retrieved without a handle (or saved sessions without a handle).cli/auth/whoami/register.ts:fetchAccount({ sessionToken, throwOnError: true }), printingFailed to fetch account details: <error>to stderr and settingprocess.exitCode = 1on lookup failures instead of printing@(not set)with exit code0.accountId/sessionIdwhenTSCIRCUIT_TOKENis active.cli/auth/login/register.ts:@undefinedand avoiding stale cached handles whenTSCIRCUIT_TOKENis set.tests/lib/registry-api/fetch-account.test.tscovering default offline fallback,throwOnErroron HTTP 503/401 (session_expired)/403/429, network errors, malformed JSON, missingaccountobjects, accounts with/withouttscircuit_handle, and skip/unauthenticated paths.tests/lib/push-snippet-account-lookup.test.tscoveringpushSnippet(503 with cached handle present, 401session_expired, network error, malformed payload, 200 without handle, 200 with handle proceeding to publish),auth whoami(503 failure vs 200 without handle), andauth login(offline-tolerant 503 without@undefined).Verification
bun test tests/lib/registry-api/fetch-account.test.ts tests/lib/push-snippet-account-lookup.test.ts tests/lib/cli-config-token.test.ts tests/lib/registry-api/get-ky-session-expired.test.ts tests/lib/registry-api/get-ky-error-output.test.ts— 28 pass, 0 fail.bun test --timeout 30000 tests/cli/auth/whoami.test.ts tests/cli/auth/login.test.ts tests/cli/push/push15-environment-token.test.ts— 4 pass, 0 fail.bunx tsc --noEmit— passed (exit 0).bunx biome formaton all 7 modified/added files andbunx biome checkon core/new files — passed (exit 0).bun run build— passed (exit 0)./accounts/getresponse:tsci push index.circuit.tsxexits with code1and reportsCould not verify your account for publishing: FAIL [503]: POST /accounts/get.tsci auth whoamiexits with code1and reportsFailed to fetch account details: FAIL [503]: POST /accounts/get.tsci auth loginexits with code0and reportsAlready logged in! Use tsci logout to switch accounts..